package cn.openea.perpartner.payment.web.subpoints.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.openea.perpartner.payment.web.subpoints.entity.SubPointLog;
import cn.openea.perpartner.payment.web.subpoints.mapper.SubPointLogMapper;
import cn.openea.perpartner.payment.web.subpoints.service.ISubPointLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * (SubPaymentRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-06-27 14:45:50
 */
@Service("subPaymentLogService")
public class SubPointLogServiceImpl extends ServiceImpl<SubPointLogMapper, SubPointLog> implements ISubPointLogService {
    @Override
    public List<SubPointLog> selectList(String userId, String sceneId, String operType) {
        LambdaQueryWrapper<SubPointLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SubPointLog::getUserid,userId);
        if(StrUtil.isNotBlank(sceneId)){
            wrapper.eq(SubPointLog::getSceneId,sceneId);
        }
        if (StrUtil.isNotBlank(operType)){
            wrapper.eq(SubPointLog::getOpertype,operType);
        }
        wrapper.orderByDesc(SubPointLog::getCreatetime);
        return this.list(wrapper);
    }
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    @Override
    public boolean save(SubPointLog paymentLog, String operType) {
        paymentLog.setOpertype(operType);
        return this.save(paymentLog);
    }

}
